home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 376-400 / disk_388 / free / errors.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  3KB  |  107 lines

  1. /***************************************************************************
  2.  * errors.c:    Error-handling functions.
  3.  *
  4.  * Part of...
  5.  *
  6.  *    FREE:    Display free space on your disk volumes.
  7.  *        Author:  Daniel Jay Barrett, barrett@cs.jhu.edu.
  8.  *
  9.  * This program is Freely Distributable.  Make all the copies you want
  10.  * and give them away.  Use this code in any way you like.
  11. ***************************************************************************/
  12.  
  13. #include "free.h"
  14.  
  15. /* The user made a mistake in invoking the program.  Give 'em hell. */
  16.  
  17. void Usage(char *prog)
  18. {
  19.     fprintf(stderr, "%s%s%s Version %s by Daniel Jay Barrett.\n",
  20.         HI_ON, prog, HI_OFF, VERSION);
  21.     fprintf(stderr, "Inspired by Tom Smythe's FREE on Fish Disk 66.\n");
  22.     fprintf(stderr, "This program is Freely Distributable.\n\n");
  23.  
  24.     fprintf(stderr,
  25. "Usage: %s%s%s [-%c%c] [-%c BYTES] [-%c LENGTH] [volume1] [volume2] ...\n\n",
  26.        HI_ON, prog, HI_OFF, OPT_BLOCKS, OPT_REQUESTORS, OPT_MALLOC,
  27.        OPT_VOLUME_NAME_LEN);
  28.  
  29.     fprintf(stderr, "\t-%c:\tDisplay blocks instead of bytes.\n",
  30.         OPT_BLOCKS);
  31.     fprintf(stderr, "\t-%c:\tEnable volume requestors.\n", OPT_REQUESTORS);
  32.     fprintf(stderr, "\t-%c:\tAllocate BYTES of memory for the output.\n",
  33.         OPT_MALLOC);
  34.     fprintf(stderr,
  35.        "\t-%c:\tSpecify the max LENGTH of a volume name (1 - %d).\n",
  36.        OPT_VOLUME_NAME_LEN, MAX_NAME_LEN);
  37.     
  38.     fprintf(stderr, "\nIf no volumes given, the environment ");
  39.     fprintf(stderr, "variable `%s' is used.\n", ENV_VARIABLE);
  40.     fprintf(stderr, "Example:  setenv %s \"df0:,df1:,ram:,dh0:\"\n\n",
  41.         ENV_VARIABLE);
  42.  
  43.     fprintf(stderr, "If %s does not exist,\n", ENV_VARIABLE);
  44.     fprintf(stderr, "then the following devices are checked by default:\n");
  45.     fprintf(stderr, "\t%s\n\n", DEFAULT_VOLUMES);
  46. }
  47.  
  48.  
  49. /* Given a particular error code, print the appropriate error message. */
  50.  
  51. void ErrorMsg(ERROR code)
  52. {
  53.     if (code)
  54.         fprintf(stderr, "ERROR! ");
  55.     switch (code)
  56.     {
  57.         case NO_ERROR:
  58.             break;
  59.         case ERROR_TOO_SMALL:
  60.             fprintf(stderr,
  61.                "%s%d%s%c%s%s",
  62.                "The output is too long to fit in ",
  63.                memSize, " bytes.\nUse the -", OPT_MALLOC,
  64.                " option to increase memory size.\n",
  65.                "Output TRUNCATED and possibly not accurate.\n\n");
  66.             break;
  67.         case ERROR_CANT_MALLOC:
  68.             fprintf(stderr, "Can't allocate that much memory!\n");
  69.             break;
  70.         case ERROR_FORMAT_STRING:
  71.             fprintf(stderr, "%s%c%s%d%s\n",
  72.                 "Your -", OPT_VOLUME_NAME_LEN,
  73.                  " value must be an integer between 1 and ",
  74.                 MAX_NAME_LEN, ".");
  75.             break;
  76.         case ERROR_IMPOSSIBLE:
  77.            fprintf(stderr, "This should never happen!\n");
  78.            fprintf(stderr, "There must be a bug in this program.\n");
  79.            break;
  80.     }
  81. }
  82.  
  83.  
  84. /* If the user specified an illegal value (0 or less) as the argument of
  85.  * the option OPT_VOLUME_NAME_LEN, complain!  Then use the default value. */
  86.  
  87. void CheckVolumeNameLen(int *nameLen)
  88. {
  89.     if (*nameLen < 1 || *nameLen > MAX_NAME_LEN)
  90.     {
  91.         ErrorMsg(ERROR_FORMAT_STRING);
  92.         *nameLen = DEFAULT_NAME_LEN;
  93.     }
  94. }
  95.  
  96.  
  97. /* If the user specified an invalid volume name, complain!  A valid name
  98.  * must have at least 1 character (really two, but...), and its last
  99.  * character must be VOLUME_END_CHAR. */
  100.  
  101. int ValidDriveName(char *drive)
  102. {
  103.     int len = strlen(drive);
  104.  
  105.     return((len > 0)  &&  (drive[len-1] == VOLUME_END_CHAR));
  106. }
  107.